<template>
  <div class="navbar">
    <el-button type="warning" @click="jumpusermanagement">用户管理</el-button
    ><br /><br /><br /><br />
    <el-button type="primary" @click="jumpnewsmanagement">新闻管理</el-button
    ><br /><br /><br /><br />
    <el-button type="success" @click="jumptopicmanagement">专题管理</el-button
    ><br /><br /><br /><br />
    新闻任务:{{ this.update_news }}
    <el-button :disabled="IsNewsAlive" type="danger" @click="revivenews"
      >复活</el-button
    >
    <br />
    热词任务:{{ this.update_hotwords }}
    <el-button :disabled="IsHotwordsAlive" type="danger" @click="revivehotwords"
      >复活</el-button
    >
    <br />
    情感分析任务:{{ this.update_sentiment }}
    <el-button
      :disabled="IsSentimentAlive"
      type="danger"
      @click="revivesentiment"
      >复活</el-button
    >
    <br />
    聚类任务:{{ this.update_cluster }}
    <el-button :disabled="IsClusterAlive" type="danger" @click="revivecluster"
      >复活</el-button
    >
    <br />
    <!-- 爬虫任务:{{this.spider}}
      <el-button :disabled="IsSpiderAlive" type="warning" @click="revivespider">复活</el-button> -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      update_news: "alive",
      update_hotwords: "alive",
      update_sentiment: "alive",
      update_cluster: "alive",
      // spider:'alive',
      IsNewsAlive: true,
      IsHotwordsAlive: true,
      IsSentimentAlive: true,
      IsClusterAlive: true,
      // IsSpiderAlive:true,
    };
  },
  mounted: function () {
    setInterval(this.Isdead(), 3600000);
  },
  methods: {
    Isdead() {
      this.$axios({
        method: "get",
        url: "/api/heart/al_updateactive",
      }).then((res) => {
        console.log("ress:", res);
        if (res.data.update_News_task == 0) {
          //死了
          this.update_news = "dead";
          this.IsNewsAlive = false;
        }
        if (res.data.update_Hotwords_task == 0) {
          //死了
          this.update_hotwords = "dead";
          this.IsHotwordsAlive = false;
        }
        if (res.data.update_Sentiment_task == 0) {
          //死了
          this.update_sentiment = "dead";
          this.IsSentimentAlive = false;
        }
        if (res.data.update_Cluster_task == 0) {
          //死了
          this.update_cluster = "dead";
          this.IsClusterAlive = false;
        }
        //进程状态，字典
      });
    },
    revivenews() {
      this.$axios({
        method: "post",
        url: "/api/heart/al_restart",
        data: {
          restartprocess: "update_News_task",
        },
      }).then((res) => {
        console.log("restart news tasks successfully.");
        this.update_news = "alive";
        this.IsNewsAlive = true;
      });
    },
    revivecluster() {
      this.$axios({
        method: "post",
        url: "/api/heart/al_restart",
        data: {
          restartprocess: "update_Cluster_task",
        },
      }).then((res) => {
        console.log("restart Cluster tasks successfully.");
        this.update_cluster = "alive";
        this.IsClusterAlive = true;
      });
    },
    revivehotwords() {
      this.$axios({
        method: "post",
        url: "/api/heart/al_restart",
        data: {
          restartprocess: "update_Hotwords_task",
        },
      }).then((res) => {
        console.log("restart Hotwords tasks successfully.");
        this.update_hotwords = "alive";
        this.IsHotwordsAlive = true;
      });
    },
    revivesentiment() {
      this.$axios({
        method: "post",
        url: "/api/heart/al_restart",
        data: {
          restartprocess: "update_Sentiment_task",
        },
      }).then((res) => {
        console.log("restart Sentiment tasks successfully.");
        this.update_sentiment = "alive";
        this.IsSentimentAlive = true;
      });
    },
    // revivespider(){
    //   this.$axios({
    //     method:'post',
    //     url: '/api/heart/sp_restart',
    //     data:{
    //       restartprocess:'update_Sentiment_task'
    //     }
    //   }).then(res=>{
    //     this.spider='alive'
    //     this.IsSpiderAlive=true
    //   })
    // },
    jumpusermanagement() {
      const self = this;
      self
        .$axios({
          method: "post",
          url: "/api/user/all_users",
          headers: {
            Authorization: window.sessionStorage.getItem("token"),
          },
        })
        .then((res) => {
          if (res.data.statusCode == 1) {
            // alert(res.data.message)
            // window.location.replace('/mainlayout/usermanagement')
            this.$router.push({
              name: "userManagement",
            });
          } else {
            alert(res.data.message);
          }
          // window.location.reload()
        })
        .catch((e) => {
          alert(e.response.data.message);
        });
    },
    jumpnewsmanagement() {
      // window.location.replace('/mainlayout/newsManagement')
      this.$router.push({
        name: "newsManagement",
      });
    },
    jumptopicmanagement() {
      // window.location.replace('/mainlayout/topicManagement')
      this.$router.push({
        name: "topicManagement",
      });
    },
  },
};
</script>